package com.plugins.server;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class AppServer {
	
	public static void main(String[] args) {
		String EXCHANGE_NAME = "followuser";
		String QUEUE_NAME = "go";
		String ROUTEKEY = "follow:user";
		while(true){
			try{
				ConnectionFactory factory = new ConnectionFactory();
				factory.setHost("127.0.0.1");
				factory.setUsername("yanghui");
				factory.setPassword("yanghui");
				factory.setRequestedHeartbeat(5);
				factory.setAutomaticRecoveryEnabled(true);
				Connection connection = factory.newConnection();
				Channel channel = connection.createChannel();
				channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);
				channel.queueDeclare(QUEUE_NAME, true, false, false, null);
				channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTEKEY);
				channel.basicPublish(EXCHANGE_NAME, ROUTEKEY, null, "test".getBytes());
				channel.close();
				connection.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
}
